package com.csweimei.rentmanagementtreasure.enterprise.viewModel;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.chad.library.BR;
import com.csweimei.rentmanagementtreasure.R;
import com.csweimei.rentmanagementtreasure.base.AppConfig;
import com.csweimei.rentmanagementtreasure.enterprise.act.StaffDetailActivity;
import com.csweimei.rentmanagementtreasure.enterprise.act.VipActivity;
import com.csweimei.rentmanagementtreasure.http.entity.DealHouseListBean;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class DealHouseItemPVM extends MultiItemViewModel {
    DealHouseVM dealHouseVM;
    public DealHouseItemPVM(@NonNull BaseViewModel viewModel) {
        super(viewModel);
        dealHouseVM = (DealHouseVM) viewModel;
    }

    public ObservableField<DealHouseListBean.DataDTO> entity = new ObservableField<>();

    public ObservableList<DealHouseItemCVM> observableList = new ObservableArrayList<>();
    public ItemBinding<DealHouseItemCVM> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_deal_house_c);

    public void setData(DealHouseListBean.DataDTO bean) {
        entity.set(bean);
        observableList.clear();
        if (bean.getLList().size() > 0){
            for (DealHouseListBean.DataDTO.LListDTO houses : bean.getLList()) {
                DealHouseItemCVM dealHouseItemCVM = new DealHouseItemCVM(viewModel);
                dealHouseItemCVM.setData(houses);
                observableList.add(dealHouseItemCVM);
            }
        }


    }

    public BindingCommand itemClick  = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (AppConfig.isEntVip()){
                Bundle bundle = new Bundle();
                bundle.putString(AppConfig.BUNDLE_KEY,entity.get().getUserid()+"");
                bundle.putString(AppConfig.BUNDLE_KEY2,dealHouseVM.companyid.get()+"");
                viewModel.startActivity(StaffDetailActivity.class,bundle);
            }else {
                ToastUtils.showShort("您还未开通企业服务，请前往购买相关服务");
                viewModel.startActivity(VipActivity.class);
            }

        }
    });
}
